// AutoCadGeometry.cpp: implementation of the AutoCadGeometry class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AutoCadGeometry.h"
#include "UEEntityOperation.h"
#include "PersistentObject.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

AutoCadGeometry::AutoCadGeometry()
{

}

AutoCadGeometry::~AutoCadGeometry()
{

}

AutoCadGeometry::AutoCadGeometry(Element *pElement)
{
	ASSERT(pElement!=NULL);
	this->m_pElement = pElement;
}


void AutoCadGeometry::Erase()
{
	AcDbEntity* pEntity = CUEEntityOperation::OpenEntityWrite(this->m_EntityHandle);
	ASSERT(pEntity);
	
	pEntity->erase();
	pEntity->close();
}

AcDbHandle& AutoCadGeometry::GetHandle()
{
	ASSERT( !m_EntityHandle.isNull() );
	return m_EntityHandle;
}

void AutoCadGeometry::Update(BOOL bFlag)
{
	PersistentObject* pPerObj 
		= dynamic_cast<PersistentObject*>(this->GetElement());
	ASSERT(pPerObj);

	if (pPerObj->IsCreateState())
	{
		this->CreateGeometry();
	}
	else if (pPerObj->IsDeleteState())
	{
		this->Erase();
	}
	else if (pPerObj->IsModifyGeoState())
	{
		this->Erase();
		this->CreateGeometry();
	}
	else if (pPerObj->IsModifyPrjState())
	{
		return ;
	}
	else if (pPerObj->IsTransformState())
	{
		UESoft::ErrorStatus es = this->TransformBy();

		if (es != UESoft::eOk)
		{
			return ;
		}
	}
	else
	{
		return ;
	}
	return ;
}
